package com.pata.skin
{
	import flash.display.GradientType;
	import flash.display.Shape;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	
	/**
	 * @data	2011-4-6	
	 * @author	pata
	 */
	public class GradientShape extends Shape
	{
		/**
		 * 
		 * 自上而下的渐变图形
		 * @param fillColors	
		 * @param borderColors
		 * @param borderSize
		 */
		public function GradientShape(width:Number, height:Number, fillColors:Object, borderColors:Object = 0, fillAlpha:Number = 1, borderAlpha:Number = 1, borderSize:Number = 1)
		{
			this.graphics.lineStyle(borderSize, borderAlpha);
			var m:Matrix = new Matrix();
			m.createGradientBox(width , height, Math.PI/2);
			if(typeof(fillColors) === "Object" && (fillColors is Array) && typeof(borderColors) === "Object" && (borderColors is Array))
			{				
				this.graphics.lineGradientStyle(GradientType.LINEAR, borderColors as Array, [borderAlpha, borderAlpha], [0, 255], m);
				this.graphics.beginGradientFill(GradientType.LINEAR, fillColors as Array, [fillAlpha, fillAlpha], [0, 255], m);
			}else if(typeof(fillColors) === "number" && typeof(borderColors) === "number")
			{
				this.graphics.lineStyle(borderSize, int(borderColors), borderAlpha);
				this.graphics.beginFill(int(fillColors), fillAlpha);
			}else if(typeof(fillColors) === "object" && typeof(borderColors) === "number" && (fillColors is Array))
			{				
				this.graphics.lineStyle(borderSize, int(borderColors), borderAlpha);
				this.graphics.beginGradientFill(GradientType.LINEAR, fillColors as Array, [fillAlpha, fillAlpha], [0, 255], m);
			}else if(typeof(fillColors) === "number" && typeof(borderColors) === "object" && (borderColors is Array))
			{
				this.graphics.lineGradientStyle(GradientType.LINEAR, borderColors as Array, [borderAlpha, borderAlpha], [0, 255], m);
				this.graphics.beginFill(int(fillColors), fillAlpha);
			}
			this.graphics.drawRect(0, 0, width, height);
			this.graphics.endFill();
			
			this.scale9Grid = new Rectangle(borderSize + 2, borderSize + 2, width - borderSize * 2 - 4, height - borderSize * 2 - 4);
		}
	}
}